package com.xucy.springboot.security;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @Author xucy
 * @Date 2019-09-01 12:58
 * @Description 定义自己的密码加密
 **/

public class MyPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence charSequence) {
        //使用spring security带的md5加密
        BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();

        return bCryptPasswordEncoder.encode(charSequence);
    }

    /**
     * 匹配密码是否一致
     *
     * @Author xucy
     * @Date 13:01 2019-09-01
     * @param
     * @return
     */
    @Override
    public boolean matches(CharSequence charSequence, String s) {
        BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();
        return bCryptPasswordEncoder.matches(charSequence,s);
    }
}
